package ControllerSrevlet;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import MYJDBC.jdbc;

/**
 * Servlet implementation class VideoGoodJob
 */
@WebServlet("/VideoGoodJob")
public class VideoGoodJob extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public VideoGoodJob() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("UTF-8");
		String videoid =  request.getParameter("videoid");
		int vid = Integer.parseInt(videoid); 
		int num = 0;
		
		jdbc jc = new jdbc();
		ResultSet rs =  jc.SqlRs("select * from video_table where videoid = "+vid+";");
		try {
			while(rs.next()) {
				num = rs.getInt("videogoodjob");
			}
			num = num + 1;
			jc.QueryClose();
			jc.SqlUpdate("update video_table set videogoodjob = "+num+" where videoid = "+vid+";");
			jc.UpdateClose();
			response.sendRedirect("BlueVideoPlay?VideoID="+vid);
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
